﻿using System;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;

namespace Kz.Telegram.Bot.Console.HandleUpdate
{
    public class ChatMemberHandler : IHandler
    {
        public Task Handle(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
        {
            var member = update.ChatMember!;

            //群组信息
            var group_id = member.Chat.Id;
            var group_name = member.Chat.Title;
            var group_username = member.Chat.Username;

            //来源用户
            var from_id = member.From.Id;
            var from_username = member.From.Username;

            switch (member.NewChatMember.Status)
            {
                case ChatMemberStatus.Creator:
                    break;
                case ChatMemberStatus.Administrator:
                    break;
                case ChatMemberStatus.Member:   //用户加入
                    {
                        System.Console.WriteLine($"用户:{member.From.FirstName} {member.From.LastName} 加入频道:{group_name}");
                    }
                    break;
                case ChatMemberStatus.Left:     //用户离开
                    {
                        System.Console.WriteLine($"用户:{member.From.FirstName} {member.From.LastName} 离开频道:{group_name}");
                    }
                    break;
                case ChatMemberStatus.Kicked:
                    break;
                case ChatMemberStatus.Restricted:
                    break;
                default:
                    break;
            }

            return Task.CompletedTask;
        }
    }
}
